{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e7888915",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:root:Watch out!\n"
     ]
    }
   ],
   "source": [
    "import logging\n",
    "logging.warning('Watch out!')  # 将打印一条消息到控制台\n",
    "logging.info('I told you so')  # 将不打印任何消息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8c6ad6cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-05-14 10:40:48,929 [DEBUG] example_function: 这是一个调试日志\n"
     ]
    }
   ],
   "source": [
    "import logging\n",
    "\n",
    "# 配置日志格式，包含函数名\n",
    "logging.basicConfig(\n",
    "    level=logging.DEBUG,\n",
    "    format=\"%(asctime)s [%(levelname)s] %(funcName)s: %(message)s\"\n",
    ")\n",
    "\n",
    "def example_function():\n",
    "    logging.debug(\"这是一个调试日志\")\n",
    "\n",
    "example_function()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "501d8fe7",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "WARNING:root:这是一条 warning 日志\n"
     ]
    }
   ],
   "source": [
    "import logging\n",
    "\n",
    "logging.info(\"这是一条 info 日志\")\n",
    "logging.warning(\"这是一条 warning 日志\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
